namespace Brjnk.GpxExplorer.Localization
{
    using System;
    using System.ComponentModel;
    using System.Windows;

    /// <summary>
    /// </summary>
    public class LocalizationString : System.ComponentModel.INotifyPropertyChanged, IWeakEventListener
    {
        private string key;
        private object element;

        public LocalizationString(string key, object element)
        {
            this.key = key;
            this.element = element;
            System.ComponentModel.PropertyChangedEventManager.AddListener(LocalizationManager.Instance, this, "");
        }

        public string Key { get { return key; } }

        public object Element { get { return element; } }

        public Type Type { get { return element.GetType(); } }

        public string Text
        {
            get { return LocalizationManager.Instance[key]; }
            set
            {
                LocalizationManager.Instance.Update(key, value);
                OnPropertyChanged("Text");
            }
        }

        public void Resume()
        {
            LocalizationManager.Instance.Resume(key);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
        {
            OnPropertyChanged("Text");
            return true;
        }
    }
}